SRC_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
BIN_DIR = $(abspath ${SRC_DIR}/../../../bin)
INC_DIR = $(abspath ${SRC_DIR}/include)

OUT = packet-counter.o
SRC = $(patsubst %.o,%.c,${OUT})

CFLAGS = -O2 -D__KERNEL__ \
         -Wno-unused-value \
		 -Wno-pointer-sign \
	     -Wno-compare-distinct-pointer-types

all: ${BIN_DIR}/${OUT}

${BIN_DIR}/${OUT}: ${SRC_DIR}/${SRC}
	clang -I${INC_DIR} ${CFLAGS} -emit-llvm -c -g $< -o - | llc -march=bpf -filetype=obj -o $@

clean:
	rm -f ${BIN_DIR}/${OUT}

test:
	cd ${SRC_DIR} && ./test.sh
